package com.tmc.entity.inthotel;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * ToCitylocation entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see entity.ToCitylocation
 * @author MyEclipse Persistence Tools
 */

public class ToCitylocationDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(ToCitylocationDAO.class);
	// property constants
	public static final String CITY_LOCATION_PROVIDER = "cityLocationProvider";
	public static final String CITY_LOCATION_STATUS = "cityLocationStatus";
	public static final String LOCATION = "location";
	public static final String DESTINATION_CODE = "destinationCode";
	public static final String CITY = "city";
	public static final String CITY_DESTINATION_ID = "cityDestinationId";

	public void save(ToCitylocation transientInstance) {
		log.debug("saving ToCitylocation instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ToCitylocation persistentInstance) {
		log.debug("deleting ToCitylocation instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ToCitylocation findById(java.lang.Integer id) {
		log.debug("getting ToCitylocation instance with id: " + id);
		try {
			ToCitylocation instance = (ToCitylocation) getSession().get(
					"entity.ToCitylocation", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ToCitylocation instance) {
		log.debug("finding ToCitylocation instance by example");
		try {
			List results = getSession().createCriteria("entity.ToCitylocation")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ToCitylocation instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ToCitylocation as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCityLocationProvider(Object cityLocationProvider) {
		return findByProperty(CITY_LOCATION_PROVIDER, cityLocationProvider);
	}

	public List findByCityLocationStatus(Object cityLocationStatus) {
		return findByProperty(CITY_LOCATION_STATUS, cityLocationStatus);
	}

	public List findByLocation(Object location) {
		return findByProperty(LOCATION, location);
	}

	public List findByDestinationCode(Object destinationCode) {
		return findByProperty(DESTINATION_CODE, destinationCode);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByCityDestinationId(Object cityDestinationId) {
		return findByProperty(CITY_DESTINATION_ID, cityDestinationId);
	}

	public List findAll() {
		log.debug("finding all ToCitylocation instances");
		try {
			String queryString = "from ToCitylocation";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ToCitylocation merge(ToCitylocation detachedInstance) {
		log.debug("merging ToCitylocation instance");
		try {
			ToCitylocation result = (ToCitylocation) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ToCitylocation instance) {
		log.debug("attaching dirty ToCitylocation instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ToCitylocation instance) {
		log.debug("attaching clean ToCitylocation instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}